﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SolutionCrapFinder
{
    public partial class SCFProjectSettingsForm : Form
    {
        // members
        SCFProjectSettings m_settings;

        public SCFProjectSettingsForm()
        {
            InitializeComponent();
        }

        public SCFProjectSettings Settings
        {
            set { m_settings = value; }
            get { return m_settings; }
        }

        private void InitializeSettings()
        {
            StringBuilder sb = new StringBuilder();
            foreach (string s in m_settings.m_solutions)
            {
                sb.AppendLine(s);
            }
            richTextBox1.Text = sb.ToString();
            richTextBox1.Text = richTextBox1.Text.Substring(0, richTextBox1.Text.Length - 1);
            sb.Clear();

            textBox1.Text = m_settings.m_directory;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.CheckFileExists = true;
            dlg.Filter = "Solution files (*.sln)|*.sln";
            dlg.ShowDialog();
            if (dlg.FileName != null && dlg.FileName.Length != 0)
            {
                richTextBox1.AppendText(String.Format("\n{0}", dlg.FileName));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            dlg.ShowDialog();
            if (dlg.SelectedPath != null && dlg.SelectedPath.Length != 0)
            {
                textBox1.Text = dlg.SelectedPath;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            m_settings.m_solutions = new List<string>(richTextBox1.Text.Split('\n'));
            m_settings.m_directory = textBox1.Text;
            DialogResult = DialogResult.OK;
            Close();
        }

        private void SCFProjectSettingsForm_Load(object sender, EventArgs e)
        {
            if (m_settings == null)
            {
                m_settings = new SCFProjectSettings();
            }
            InitializeSettings();
        }
    }
}
